import java.awt.geom.Point2D;
import java.util.*;


public class Casteljau {

    private float[] x;
    private float[] y;
    private int n;
    private float[][] b;

    private List<Point2D> controlList;
    
    public Casteljau(float[] x, float[] y, int n) {
        //require x.length = y.length = n
        this.x = x;
        this.y = y;
        this.n = n;
        this.b = new float[n][n];
    }

    // not used at the moment...
    public Casteljau(List<Point2D> l) {
        this.controlList = l;
    }

    
    private void init(float[] initialValues) {
        for (int i = 0; i < n; i++) {
            b[0][i] = initialValues[i];
        }
    }

    private float evaluate(float t, float[] initialValues) {
        init(initialValues);
        for (int j = 1; j < n; j++) {
            for (int i = 0; i < n - j; i++) {
                b[j][i] = b[j-1][i] * (1-t) + b[j-1][i+1] * t;
            }
        }
        return(b[n-1][0]);
    }

    public float[] getXYvalues(float t) {
    	float xVal = evaluate(t, x);
    	float yVal = evaluate(t, y);
        return new float[] {xVal, yVal};
    }

  
    
}    